package simulation;

public class countAndSay {
    public String countAndSay(int n) {
        String s = "1";
        for(int i =1;i<n;i++) {
            StringBuilder ret = new StringBuilder();
            int len = s.length();
            int left = 0;
            int right = 0;
            while(right < len ) {
                while(right < len&& s.charAt(left) == s.charAt(right)) right++;
                ret.append(Integer.toString(right-left));
                ret.append(s.charAt(left));
                left = right;
            }
            s = ret.toString();
        }
        return s;

    }
}
